<template>
  <a-modal v-model="show" title="任务表单" :confirmLoading="confirmLoading"
           :forceRender="true"
          @cancel="()=>show=false" @ok="haneleOk"
           width="80%" :mast="false">
    <FormIframe ref="formIframeRef" :buttonShow="false"></FormIframe>
  </a-modal>
</template>

<script>
    import FormIframe from './FormIframe'
    import { postAction } from '../../../api/manage'
    import { activitiFormUrl, activitiTaskUrl } from '../../../api/url';
    import { concatUrl } from '../../../utils/util'
    export default {
      name: 'FormModal',
      components: { FormIframe },
      data(){
        return {
          show:false,
          confirmLoading:false,
          formData:{
            deploymentId:'',
            taskId:'',
            formKey:'',
            formProperties:[],
          },
        }
      },
      methods:{
          haneleOk(){
            let data = this.$refs.formIframeRef.getFormData();
            data.then(res=>{
              this.confirmLoading = true;
              let url = "";
              if(this.formData.taskId){
                url = activitiTaskUrl.complate+"/"+this.formData.taskId;
              }else {
                url = activitiFormUrl.startProcess+"/"+this.formData.deploymentId;
              }
              postAction(url, res)
                .then(res=>{
                  if(res.success){
                    this.$message.success(res.message);
                    this.show = false;
                  }
                }).finally(()=>{
                this.confirmLoading = false;
              })

            })
          },
          showData(formData ){
            this.show = true;
            this.formData= formData;
            this.$nextTick(()=>{
              this.$refs.formIframeRef.loadData(formData);
            })
          }
      }
    }
</script>

<style scoped>

</style>